import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

  const routes = [
    {
      path: "/home",
      component: ()=>import("../components/home/Home")
    },
    {
      path: "/tag/:tagId",
      component: ()=>import("../components/tag/Tag")
    },
    {
      path: "/tag",
      redirect: "/tag/0"
    },
    {
      path: "/archive",
      component: () => import("../components/archive/Archive")
    },
    {
      path: "/information",
      component: () => import("../components/information/Information")
    },
    {
      path: "/article/:articleId",
      component: () => import("../components/article/Article")
    },
    {
      path: "/",
      redirect: "/home"
    },
    {
      path: "*",
      component: () => import("../components/error/Error")
    }

]

const router = new VueRouter({
  mode: 'history',
  base: '/',
  routes
})

// 解决重复跳转抛异常问题
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};

export default router
